package com.util;

import java.sql.*;

public class JDBCUtil {
    static String driver = "com.mysql.cj.jdbc.Driver";
    static String url = "jdbc:mysql:///mydb?useSSL=false&serverTimezone=UTC";
    static String username = "root";
    static String password = "songhao0517";
    static Connection conn = null;

    public static Connection getCon(){
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url,username,password);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return conn;
    }

    public static void colse(ResultSet rs, PreparedStatement pstm, Connection conn) throws SQLException {
        if (rs != null) {
            rs.close();
        }
        if (pstm != null){
            pstm.close();
        }
        if (conn != null){
            conn.close();
        }
    }
    public static void colse(PreparedStatement pstm,Connection conn) throws SQLException {
        if (pstm != null){
            pstm.close();
        }
        if (conn != null){
            conn.close();
        }
    }
}
